home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / util / wb / sysi2.lha / dispatch.c < prev    next >
C/C++ Source or Header  |  1997-02-12  |  14KB  |  572 lines

  1. #define DEBUG
  2. #include <debug.h>
  3. #include "sysi2.h"
  4.  
  5. extern LONG Enabled;
  6.  
  7. void Rescale(struct SysIData *SIData, struct DrawInfo *DI, UWORD Width, UWORD Height);
  8.  
  9. ULONG __saveds __asm Dispatcher(register __a0 Class *C, register __a2 struct Image *O, register __a1 Msgs M )
  10. {
  11.   struct SysIData *sidata;
  12.   struct Image *object;
  13.   ULONG retval=0;
  14.  
  15.   switch(M->MethodID)
  16.   {
  17.     case OM_NEW:
  18.       {
  19.         struct DrawInfo *di;
  20.         
  21.         di=(struct DrawInfo *)GetTagData(SYSIA_DrawInfo,0, M->opSet.ops_AttrList);
  22.         
  23.         if(di)
  24.         {
  25.           if(object=(struct Image *)DoSuperMethodA(C,(Object *)O,(Msg)M))
  26.           {
  27.             sidata=INST_DATA(C, object);
  28.             
  29.             sidata->si_Which   =GetTagData(SYSIA_Which,   0, M->opSet.ops_AttrList);;
  30.             sidata->si_DrawInfo=di;
  31.             Rescale(sidata,di,O->Width,O->Height);
  32.           }
  33.         }
  34.         retval=(ULONG)object;
  35.       }
  36.       break;
  37.  
  38.     case IM_DRAWFRAME:
  39.     case IM_DRAW:
  40.       if(Enabled)
  41.         retval=RenderImage(C,O,(Msgs)M);
  42.       else
  43.         retval=DoSuperMethodA(C,O,M);
  44.       break;
  45.  
  46.     default:
  47.       retval=DoSuperMethodA(C,(Object *)O,(Msg)M);
  48.       break;
  49.   }
  50.   return(retval);
  51. }
  52.  
  53. #define SI2_INACTIVE    1<<0
  54. #define SI2_SELECTED    1<<1
  55. #define SI2_DISABLED    1<<2
  56.  
  57. ULONG __saveds RenderImage(Class *C, struct Image *Image, Msgs M)
  58. {
  59.   struct DrawInfo *di;
  60.   struct SysIData *sidata;
  61.   struct RastPort *rp,rirp;
  62.   LONG state;
  63.   LONG left,top,right,bottom,width,height;
  64.   LONG oleft,otop,oright,obottom,owidth,oheight;
  65.   ULONG l,
  66.         shinepen,shadowpen,backgroundpen,fillpen,
  67.         btoppen,bbotpen,bfillpen; // These are for the images button colors.
  68.   WORD w[11],h[11];
  69.   ULONG rv=1;
  70.   BOOL selected,active;
  71.  
  72.   ULONG att[]=
  73.   {
  74.     0,
  75.     SI2_SELECTED,
  76.     SI2_DISABLED,
  77.     0,
  78.     0,
  79.     SI2_INACTIVE,
  80.     SI2_INACTIVE | SI2_SELECTED,
  81.     SI2_INACTIVE | SI2_DISABLED,
  82.     SI2_SELECTED | SI2_DISABLED,
  83.   };
  84.  
  85.  
  86.   sidata=INST_DATA(C, Image);
  87.  
  88.   if(!(di=M->impDraw.imp_DrInfo))
  89.     di=sidata->si_DrawInfo;
  90.  
  91.   shinepen      =di->dri_Pens[SHINEPEN];
  92.   shadowpen     =di->dri_Pens[SHADOWPEN];
  93.   backgroundpen =di->dri_Pens[BACKGROUNDPEN];
  94.   fillpen       =di->dri_Pens[FILLPEN];
  95.   
  96.   rirp=*M->impDraw.imp_RPort;
  97.   rp=&rirp;
  98.   
  99.   SetDrMd(rp,JAM1);
  100.   SetDrPt(rp,65535);
  101.   
  102.   
  103.   if(M->MethodID==IM_DRAWFRAME)
  104.   {
  105.     Rescale(sidata,di,M->impDraw.imp_Dimensions.Width,M->impDraw.imp_Dimensions.Height);
  106.   }
  107.   else
  108.   {
  109.     Rescale(sidata,di,Image->Width,Image->Height);
  110.   }
  111.   
  112.   width =sidata->si_Width;
  113.   height=sidata->si_Height;
  114.   
  115.   oleft   =M->impDraw.imp_Offset.X;
  116.   otop    =M->impDraw.imp_Offset.Y;
  117.   left    =oleft + sidata->si_X;
  118.   top     =otop  + sidata->si_Y;
  119.   
  120.   owidth  =sidata->si_OW;
  121.   oheight =sidata->si_OH;
  122.   oright  =oleft + owidth-1;
  123.   obottom =otop  + oheight-1;
  124.  
  125.   right =left + width  -1;
  126.   bottom=top  + height -1;
  127.  
  128.   // precalculates a 10 x 10 grid for rendering.
  129.   
  130.   for(l=0;l<6;l++)
  131.   {
  132.     LONG x,y;
  133.     
  134.     x=(width  * l)/10;
  135.     y=(height * l)/10;
  136.     w[l]=x + left;
  137.     h[l]=y + top;
  138.     w[10-l]=right-x;
  139.     h[10-l]=bottom-y;
  140.   }
  141.   
  142.   state=att[M->impDraw.imp_State];
  143.   selected  =  state & SI2_SELECTED;
  144.   active    =!(state & SI2_INACTIVE);
  145.  
  146.   if(selected)
  147.   {
  148.     btoppen=shadowpen;
  149.     bbotpen=shinepen;
  150.   }
  151.   else
  152.   {
  153.     btoppen=shinepen;
  154.     bbotpen=shadowpen;
  155.   }
  156.   
  157.   if(active)
  158.     bfillpen=fillpen;
  159.   else
  160.     bfillpen=backgroundpen;
  161.   
  162.   switch(sidata->si_Which)
  163.   {
  164.     case SDEPTHIMAGE:
  165.       bfillpen=backgroundpen;
  166.     case DEPTHIMAGE:
  167.       DrawBack(rp,btoppen,bbotpen,bfillpen,left,top,right,bottom);
  168.       if(selected)
  169.       {
  170.         DrawBack(rp,shadowpen,shinepen ,bfillpen,w[4],h[4],w[8],h[8]);
  171.         DrawBack(rp,shadowpen,shinepen ,backgroundpen,w[2],h[2],w[6],h[6]);
  172.         SetAPen(rp,shadowpen);
  173.         DrawPoly(rp,3,w[6]+1,h[4],
  174.                       w[6]+1,h[6]+1,
  175.                       w[4]  ,h[6]+1);
  176.         
  177.       }
  178.       else
  179.       {
  180.         DrawBack(rp,shadowpen,shinepen ,bfillpen,w[2],h[2],w[6],h[6]);
  181.         DrawBack(rp,shadowpen,shinepen ,backgroundpen,w[4],h[4],w[8],h[8]);
  182.         SetAPen(rp,shinepen);
  183.         DrawPoly(rp,3,w[6]  ,h[4]-1,
  184.                       w[4]-1,h[4]-1,
  185.                       w[4]-1,h[6]);
  186.       }
  187.  
  188.       if(sidata->si_Which==SDEPTHIMAGE && di->dri_Version>=2) 
  189.         shadowpen=di->dri_Pens[BARTRIMPEN];
  190.  
  191.       SetAPen(rp,shadowpen);
  192.       Move(rp,left-1,top+1);
  193.         Draw(rp,left-1,bottom);
  194.       break;
  195.  
  196.     case ZOOMIMAGE:
  197.       DrawBack(rp,btoppen,bbotpen,bfillpen,left,top,right,bottom);    
  198.  
  199.       {
  200.         int s;
  201.         
  202.         if(selected)
  203.           s=6;
  204.         else
  205.           s=5;
  206.       
  207.       DrawBack(rp,shadowpen,shinepen,bfillpen,w[2],h[2],w[s-1],h[s-1]);
  208.  
  209.       SetAPen(rp,backgroundpen);
  210.       FillPoly(rp, 6,w[s],h[2],
  211.                      w[8],h[2],
  212.                      w[8],h[8],
  213.                      w[2],h[8],
  214.                      w[2],h[s],
  215.                      w[s],h[s]);
  216.       SetAPen(rp,shinepen);
  217.         DrawPoly(rp,3,w[8],h[2],
  218.                       w[8],h[8],
  219.                       w[2],h[8]);
  220.       SetAPen(rp,shadowpen);
  221.         DrawPoly(rp,5,w[2],h[8],
  222.                       w[2],h[s],
  223.                       w[s],h[s],
  224.                       w[s],h[2],
  225.                       w[8],h[2]);
  226.       }        
  227.  
  228.       SetAPen(rp,shadowpen);
  229.       Move(rp,left-1,top+1);
  230.         Draw(rp,left-1,bottom);
  231.       break;
  232.  
  233.     case SIZEIMAGE:
  234.       DrawBack(rp,btoppen,bbotpen,bfillpen,oleft,otop,oright,obottom);    
  235.  
  236.       SetAPen(rp,backgroundpen);
  237.       FillPoly(rp,3,w[8],h[1],
  238.                     w[8],h[8],
  239.                     w[1],h[8]);
  240.        
  241.       SetAPen(rp,shinepen);
  242.       Move(rp,w[1],h[8]);
  243.         Draw(rp,w[8],h[8]);
  244.         Draw(rp,w[8],h[1]);
  245.       
  246.       SetAPen(rp,shadowpen);
  247.         Draw(rp,w[1],h[8]);
  248.  
  249. /*
  250.       SetAPen(rp,backgroundpen);
  251.       FillPoly(rp,3,w[8],h[2],
  252.                     w[8],h[8],
  253.                     w[2],h[8]);
  254.        
  255.       SetAPen(rp,shinepen);
  256.       Move(rp,w[8],h[2]);
  257.         Draw(rp,w[8],h[8]);
  258.         Draw(rp,w[2],h[8]);
  259.       
  260.       SetAPen(rp,shadowpen);
  261.         Draw(rp,w[8],h[2]);
  262. */
  263.       break;
  264.  
  265.     case CLOSEIMAGE:
  266.       {
  267.         int x1,x2,y1,y2;
  268.         DrawBack(rp,btoppen,bbotpen,bfillpen,left,top,right,bottom);    
  269.         y1=4;
  270.         y2=6;
  271.       
  272.         if(selected)
  273.         {
  274.           x1=4;
  275.           x2=6;
  276.         } 
  277.         else
  278.         {
  279.           x1=2;
  280.           x2=8;
  281.         }
  282.         
  283.         SetAPen(rp,shadowpen);
  284.         Move(rp,w[x1],h[6]-1);
  285.           Draw(rp,w[x1],h[4]+1);
  286.         Move(rp,w[x1]+1,h[4]);
  287.           Draw(rp,w[x2]-1,h[4]);
  288.         
  289.         SetAPen(rp,shinepen);
  290.         Move(rp,w[x2],h[4]+1);
  291.           Draw(rp,w[x2],h[6]-1);
  292.         Move(rp,w[x2]-1,h[6]);
  293.           Draw(rp,w[x1]+1,h[6]);
  294.         Move(rp,right+1,top+1);
  295.           Draw(rp,right+1,bottom);
  296.         
  297.         SetAPen(rp,backgroundpen);
  298.         MyRectFill(rp,w[x1]+1,h[4]+1,w[x2]-1,h[6]-1);
  299.       }
  300.       break;
  301.       
  302.     case LEFTIMAGE:
  303.       DrawBack(rp,btoppen,bbotpen,bfillpen,oleft,otop,oright,obottom);          
  304.  
  305.       SetAPen(rp,backgroundpen);
  306.       FillPoly(rp,3,w[8],h[1],
  307.                     w[8],h[9],
  308.                     w[1],h[5]);
  309.       SetAPen(rp,shinepen);
  310.       Move(rp,w[8],h[1]);
  311.         Draw(rp,w[8],h[9]);
  312.         Draw(rp,w[1],h[5]);
  313.       
  314.       SetAPen(rp,shadowpen);
  315.       Move(rp,w[1],h[5]);
  316.         Draw(rp,w[8],h[1]);
  317.       break;
  318.  
  319.     case UPIMAGE:
  320.       DrawBack(rp,btoppen,bbotpen,bfillpen,oleft,otop,oright,obottom);    
  321.       
  322.       SetAPen(rp,backgroundpen);
  323.       FillPoly(rp,3,w[1],h[8],
  324.                     w[5],h[1],
  325.                     w[9],h[8]);
  326.       SetAPen(rp,shinepen);
  327.       Move(rp,w[9],h[8]);
  328.         Draw(rp,w[1],h[8]);
  329.       
  330.       SetAPen(rp,shadowpen);
  331.       Move(rp,w[1],h[8]);
  332.         Draw(rp,w[5],h[1]);
  333.         Draw(rp,w[9],h[8]);
  334.       break;
  335.  
  336.     case RIGHTIMAGE:
  337.       DrawBack(rp,btoppen,bbotpen,bfillpen,oleft,otop,oright,obottom);    
  338.  
  339.       SetAPen(rp,backgroundpen);
  340.       FillPoly(rp,3,w[9],h[5],
  341.                     w[2],h[9],
  342.                     w[2],h[1]);
  343.       
  344.       SetAPen(rp,shinepen);
  345.       Move(rp,w[9],h[5]);
  346.         Draw(rp,w[2],h[9]);
  347.         
  348.       SetAPen(rp,shadowpen);
  349.       Move(rp,w[2],h[9]);
  350.         Draw(rp,w[2],h[1]);
  351.         Draw(rp,w[9],h[5]);
  352.       break;
  353.  
  354.     case DOWNIMAGE:
  355.       DrawBack(rp,btoppen,bbotpen,bfillpen,oleft,otop,oright,obottom);    
  356.   
  357.       SetAPen(rp,backgroundpen);     
  358.       FillPoly(rp,3,w[1],h[2],
  359.                     w[9],h[2],
  360.                     w[5],h[9]);
  361.       
  362.       SetAPen(rp,shinepen);
  363.       Move(rp,w[9],h[2]);
  364.         Draw(rp,w[5],h[9]);
  365.         Draw(rp,w[1],h[2]);
  366.       
  367.       SetAPen(rp,shadowpen);
  368.       Move(rp,w[1],h[2]);
  369.         Draw(rp,w[9],h[2]);
  370.       break;
  371.  
  372. /*    case MENUCHECK:
  373.         Doesn't Work! I don't know why
  374. */
  375.  
  376.     case CHECKIMAGE:
  377.       SetAPen(rp,backgroundpen);
  378.       RectFill(rp,oleft,otop,oright,obottom);
  379.       
  380.       SetAPen(rp,shinepen);
  381.         Move(rp,w[1]+1,h[9]-2);
  382.           Draw(rp, w[1]+1,h[1]+1);
  383.           Draw(rp, w[9]-2,h[1]+1);
  384.         Move(rp,w[1]+1,h[9]);
  385.           Draw(rp, w[9],h[9]);
  386.           Draw(rp, w[9],h[1]+1);
  387.  
  388.       SetAPen(rp,shadowpen);
  389.         Move(rp,w[1],h[9]-1);
  390.           Draw(rp, w[1],h[1]);
  391.           Draw(rp, w[9]-1,h[1]);
  392.         Move(rp,w[1]+2,h[9]-1);
  393.           Draw(rp, w[9]-1,h[9]-1);
  394.           Draw(rp,w[9]-1,h[1]+2);
  395.  
  396. /*      
  397.       DrawBack(rp,shadowpen,shinepen,backgroundpen,w[1],h[1],w[9],h[9]);    
  398.       DrawBack(rp,shinepen,shadowpen,backgroundpen,w[1]+1,h[1]+1,w[9]-1,h[9]-1);    
  399. */
  400.       if(selected)
  401.       {
  402.         SetAPen(rp,di->dri_Pens[TEXTPEN]);     
  403.         
  404.         FillPoly(rp,6,w[0],h[5],
  405.                       w[1],  h[4],
  406.                       w[3],  h[6],
  407.                       w[9],  h[0],
  408.                       w[10], h[1],
  409.                       w[3],  h[8]);
  410. /*
  411.       
  412.  
  413.         SetAPen(rp,shadowpen);
  414.           Draw(rp,w[3],h[8]);
  415.           Draw(rp,w[0],h[5]);
  416. */
  417.       }
  418.       break;
  419.  
  420.     case MXIMAGE:
  421.     /*
  422.       if(state & SI2_SELECTED)
  423.         SetAPen(rp,fillpen);
  424.       else
  425.         SetAPen(rp,backgroundpen);
  426.         
  427.       FillPoly(rp,4,w[2],h[5],
  428.                     w[5],h[2],
  429.                     w[8],h[5],
  430.                     w[5],h[8]);
  431.       
  432.       SetAPen(rp,bbotpen);
  433.       Move(rp,w[0],h[5]);
  434.         Draw(rp,w[5],h[10]);
  435.         Draw(rp,w[10],h[5]);
  436.       
  437.       SetAPen(rp,btoppen);
  438.       Move(rp,w[0],h[5]);
  439.         Draw(rp,w[5],h[0]);
  440.         Draw(rp,w[10],h[5]);
  441. */
  442.  
  443.       if(selected)
  444.         SetAPen(rp,fillpen);
  445.       else
  446.         SetAPen(rp,backgroundpen);
  447.       
  448.       FillPoly(rp,16,w[10],h[4],
  449.                      w[10],h[6],
  450.                      w[9],h[8],
  451.                      w[8],h[9],
  452.                      w[6],h[10],
  453.                      w[4],h[10],
  454.                      w[2],h[9],
  455.                      w[1],h[8],
  456.                      w[0],h[6],
  457.                      w[0],h[4],
  458.                      w[1],h[2],
  459.                      w[2],h[1],      
  460.                      w[4],h[0],      
  461.                      w[6],h[0],      
  462.                      w[8],h[1],      
  463.                      w[9],h[2]);      
  464.       
  465.       SetAPen(rp,bbotpen);
  466.       Move(rp,w[9],h[2]);
  467.         Draw(rp,w[10],h[4]);
  468.         Draw(rp,w[10],h[6]);
  469.         Draw(rp,w[9],h[8]);
  470.         Draw(rp,w[8],h[9]);
  471.         Draw(rp,w[6],h[10]);
  472.         Draw(rp,w[4],h[10]);
  473.         Draw(rp,w[2],h[9]);
  474.         Draw(rp,w[1],h[8]);
  475.       SetAPen(rp,btoppen);
  476.         Draw(rp,w[0],h[6]);
  477.         Draw(rp,w[0],h[4]);
  478.         Draw(rp,w[1],h[2]);
  479.         Draw(rp,w[2],h[1]);
  480.         Draw(rp,w[4],h[0]);
  481.         Draw(rp,w[6],h[0]);
  482.         Draw(rp,w[8],h[1]);
  483.         Draw(rp,w[9],h[2]); 
  484.       break;
  485.     default:
  486.       rv=DoSuperMethodA(C,(Object *)Image,(Msg)M);
  487.   }
  488.   return(rv);
  489. }
  490.  
  491.  
  492.  
  493. void Rescale(struct SysIData *SIData, struct DrawInfo *DI, UWORD Width, UWORD Height)
  494. {
  495.   WORD ow,oh,width,height;
  496.   
  497.   SIData->si_OW =ow=width =Width;
  498.   SIData->si_OH =oh=height=Height;
  499.  
  500. //  kprintf("%8lx %8lx %ld %ld\n",SIData,DI,Width,Height);
  501.  
  502.   switch(SIData->si_Which)
  503.   {
  504.     case DEPTHIMAGE:
  505.     case ZOOMIMAGE:
  506.       width--;
  507.       break;
  508.     /* Aspect Correction for the following images */
  509.     case LEFTIMAGE:
  510.     case UPIMAGE:
  511.     case DOWNIMAGE:
  512.     case RIGHTIMAGE:
  513.     case SIZEIMAGE:
  514.       Width -=2; // area inside border
  515.       Height-=2;
  516.     case CHECKIMAGE:
  517.     case MXIMAGE:
  518.       /* I like even numbers */
  519.  
  520.       height= Width  * DI->dri_Resolution.X / (max(DI->dri_Resolution.Y,1));
  521.       width = Height * DI->dri_Resolution.Y / (max(DI->dri_Resolution.X,1));
  522.       
  523.       if(height>Height)
  524.         height=Height;
  525.       else
  526.         width=Width;      
  527.       
  528.       width &=(~1);
  529.       height&=(~1);
  530.       break;
  531.   }
  532.   SIData->si_Y=(oh-height)/2;
  533.   SIData->si_X=(ow-width)/2;
  534.   SIData->si_Width =width;
  535.   SIData->si_Height=height;
  536.  
  537. }
  538.  
  539. /*
  540.   switch(sidata->si_Which)
  541.   {
  542.     case DEPTHIMAGE:
  543.     case ZOOMIMAGE:
  544.       width--;
  545.       break;
  546.     case LEFTIMAGE:
  547.     case UPIMAGE:
  548.     case DOWNIMAGE:
  549.     case RIGHTIMAGE:
  550.     case CHECKIMAGE:
  551.     case MXIMAGE:
  552.     case SIZEIMAGE:
  553.       {
  554.         width &=(~1);
  555.         height&=(~1);
  556.         kprintf("sx=%ld sy=%ld x=%ld  y=%ld\n",sidata->si_DrawInfo->dri_Resolution.X,sidata->si_DrawInfo->dri_Resolution.Y,
  557.                                                di->dri_Resolution.X,                 di->dri_Resolution.Y);
  558.         if(di->dri_Resolution.Y > di->dri_Resolution.X)
  559.         {
  560.           height=width*di->dri_Resolution.X/di->dri_Resolution.Y;
  561.           top+=(oheight-height)/2;
  562.         }
  563.         else
  564.         {
  565.           width=height*di->dri_Resolution.Y/di->dri_Resolution.X;
  566.           left+=(owidth-width)/2;
  567.         }
  568.       }
  569.       break;
  570.   }
  571. */
  572.